// Copyright (c) 2023-2025 FlyByWire Simulations
// SPDX-License-Identifier: GPL-3.0
import { FailureDefinition } from '@flybywiresim/fbw-sdk';

// Keep in mind that the CPP code also keeps a list of failure codes: fbw-a380x\src\wasm\fbw_a380\src\failures\FailureList.h
export const A380Failure = Object.freeze({
  RapidDecompression: 21000,
  CabinFan1: 21001,
  CabinFan2: 21002,
  CabinFan3: 21003,
  CabinFan4: 21004,
  HotAir1: 21005,
  HotAir2: 21006,
  FwdIsolValve: 21007,
  FwdExtractionFan: 21008,
  BulkIsolValve: 21009,
  BulkExtractionFan: 21010,
  BulkCargoHeater: 21011,
  Fdac1Ch1: 21012,
  Fdac1Ch2: 21013,
  Fdac2Ch1: 21014,
  Fdac2Ch2: 21015,
  Tadd1: 21016,
  Tadd2: 21017,
  VcmFwd1: 21018,
  VcmFwd2: 21019,
  VcmAft1: 21020,
  VcmAft2: 21021,
  OcsmAuto1: 21022,
  OcsmAuto2: 21023,
  OcsmAuto3: 21024,
  OcsmAuto4: 21025,
  Ocsm1Ch1: 21026,
  Ocsm1Ch2: 21027,
  Ocsm2Ch1: 21028,
  Ocsm2Ch2: 21029,
  Ocsm3Ch1: 21030,
  Ocsm3Ch2: 21031,
  Ocsm4Ch1: 21032,
  Ocsm4Ch2: 21033,
  AgsApp1: 21034,
  AgsApp2: 21035,
  AgsApp3: 21036,
  AgsApp4: 21037,
  TcsApp1: 21038,
  TcsApp2: 21039,
  TcsApp3: 21040,
  TcsApp4: 21041,
  VcsApp1: 21042,
  VcsApp2: 21043,
  VcsApp3: 21044,
  VcsApp4: 21045,
  CpcsApp1: 21046,
  CpcsApp2: 21047,
  CpcsApp3: 21048,
  CpcsApp4: 21049,

  Rollout: 22001,
  FmcA: 22100,
  FmcB: 22101,
  FmcC: 22102,

  AudioManagementUnit1: 23000,
  AudioManagementUnit2: 23001,
  RadioManagementPanel1: 23002,
  RadioManagementPanel2: 23003,
  RadioManagementPanel3: 23004,
  Vhf1: 23005,
  Vhf2: 23006,
  Vhf3: 23007,

  TransformerRectifier1: 24000,
  TransformerRectifier2: 24001,
  TransformerRectifier3: 24002,
  TransformerRectifier4: 24003,
  StaticInverter: 24004,
  Generator1: 24020,
  Generator2: 24021,
  Generator3: 24022,
  Generator4: 24023,
  ApuGenerator1: 24030,
  ApuGenerator2: 24031,
  AlternatingCurrent1: 24100,
  AlternatingCurrent2: 24101,
  AlternatingCurrent3: 24102,
  AlternatingCurrent4: 24103,
  AlternatingCurrentEssential: 24104,
  AlternatingCurrentEssentialShed: 24105,
  AlternatingCurrent_247XP: 24106,
  AlternatingCurrentGndFltService: 24107,
  DirectCurrent1: 24108,
  DirectCurrent2: 24109,
  DirectCurrentEssential: 24110,
  DirectCurrent_247PP: 24111,
  DirectCurrent_309PP: 24112,
  DirectCurrentHot1: 24113,
  DirectCurrentHot2: 24114,
  DirectCurrentHot3: 24115,
  DirectCurrentHot4: 24116,
  DirectCurrentGndFltService: 24117,

  Engine1Fire: 26001,
  Engine2Fire: 26002,
  Engine3Fire: 26003,
  Engine4Fire: 26004,
  APUFire: 26005,
  MLGFire: 26006,
  Engine1LoopA: 26007,
  Engine1LoopB: 26008,
  Engine2LoopA: 26009,
  Engine2LoopB: 26010,
  Engine3LoopA: 26011,
  Engine3LoopB: 26012,
  Engine4LoopA: 26013,
  Engine4LoopB: 26014,
  APULoopA: 26015,
  APULoopB: 26016,
  MLGLoopA: 26017,
  MLGLoopB: 26018,

  Prim1: 27000,
  Prim2: 27001,
  Prim3: 27002,
  Sec1: 27003,
  Sec2: 27004,
  Sec3: 27005,
  Fcdc1: 27006,
  Fcdc2: 27007,

  GreenReservoirLeak: 29000,
  YellowReservoirLeak: 29001,
  GreenReservoirAirLeak: 29002,
  YellowReservoirAirLeak: 29003,
  GreenReservoirReturnLeak: 29004,
  YellowReservoirReturnLeak: 29005,
  GreenElecPumpAOHeat: 29006,
  GreenElecPumpBOHeat: 29007,
  YellowElecPumpAOHeat: 29008,
  YellowElecPumpBOHeat: 29009,
  EnginePump1AOHeat: 29010,
  EnginePump1BOHeat: 29011,
  EnginePump2AOHeat: 29012,
  EnginePump2BOHeat: 29013,
  EnginePump3AOHeat: 29014,
  EnginePump3BOHeat: 29015,
  EnginePump4AOHeat: 29016,
  EnginePump4BOHeat: 29017,

  Fws1: 31100,
  Fws2: 31101,
  Fws1AudioFunction: 31102,
  Fws2AudioFunction: 31103,
  FwsEcp: 31104,

  LgciuPowerSupply1: 32000,
  LgciuPowerSupply2: 32001,
  LgciuInternalError1: 32002,
  LgciuInternalError2: 32003,

  GearProxSensorDamageGearUplockLeft1: 32004,
  GearProxSensorDamageDoorDownlockRight2: 32005,
  GearProxSensorDamageGearUplockNose1: 32006,
  GearProxSensorDamageDoorUplockLeft2: 32007,

  RadioAltimeter1: 34000,
  RadioAltimeter2: 34001,
  RadioAltimeter3: 34002,
  RadioAntennaInterrupted1: 34010,
  RadioAntennaInterrupted2: 34011,
  RadioAntennaInterrupted3: 34012,
  RadioAntennaDirectCoupling1: 34020,
  RadioAntennaDirectCoupling2: 34021,
  RadioAntennaDirectCoupling3: 34022,

  Transponder1: 34003,
  Transponder2: 34004,

  Terr1: 34005,
  Terr2: 34006,
  Gpws1: 34007,
  Gpws2: 34008,

  NssAnsu1: 46001,
  NssAnsu2: 46002,
  FltOpsAnsu: 46003,
  CaptainLaptop: 46004,
  FirstOfficerLaptop: 46005,
  CaptainOit: 46006,
  FirstOfficerOit: 46007,
});

export const A380FailureDefinitions: FailureDefinition[] = [
  [21, A380Failure.RapidDecompression, 'Rapid Decompression'],
  [21, A380Failure.CabinFan1, 'Cabin Fan 1'],
  [21, A380Failure.CabinFan2, 'Cabin Fan 2'],
  [21, A380Failure.CabinFan3, 'Cabin Fan 3'],
  [21, A380Failure.CabinFan4, 'Cabin Fan 4'],
  [21, A380Failure.HotAir1, 'Hot Air Valve 1'],
  [21, A380Failure.HotAir2, 'Hot Air Valve 2'],
  [21, A380Failure.FwdIsolValve, 'Foward Cargo Isolation Valve'],
  [21, A380Failure.FwdExtractionFan, 'Foward Cargo Extraction Fan'],
  [21, A380Failure.BulkIsolValve, 'Bulk Cargo Isolation Valve'],
  [21, A380Failure.BulkExtractionFan, 'Bulk Cargo Extraction Fan'],
  [21, A380Failure.BulkCargoHeater, 'Bulk Cargo Heater'],
  [21, A380Failure.Fdac1Ch1, 'FDAC 1 Channel 1'],
  [21, A380Failure.Fdac1Ch2, 'FDAC 1 Channel 2'],
  [21, A380Failure.Fdac2Ch1, 'FDAC 2 Channel 1'],
  [21, A380Failure.Fdac2Ch2, 'FDAC 2 Channel 2'],
  [21, A380Failure.Tadd1, 'TADD Channel 1'],
  [21, A380Failure.Tadd2, 'TADD Channel 2'],
  [21, A380Failure.VcmFwd1, 'Forward VCM Channel 1'],
  [21, A380Failure.VcmFwd2, 'Forward VCM Channel 2'],
  [21, A380Failure.VcmAft1, 'Aft VCM Channel 1'],
  [21, A380Failure.VcmAft2, 'Aft VCM Channel 2'],
  [21, A380Failure.OcsmAuto1, 'Automatic Partition of OCSM 1'],
  [21, A380Failure.OcsmAuto2, 'Automatic Partition of OCSM 2'],
  [21, A380Failure.OcsmAuto3, 'Automatic Partition of OCSM 3'],
  [21, A380Failure.OcsmAuto4, 'Automatic Partition of OCSM 4'],
  [21, A380Failure.Ocsm1Ch1, 'OCSM 1 Channel 1'],
  [21, A380Failure.Ocsm1Ch2, 'OCSM 1 Channel 2'],
  [21, A380Failure.Ocsm2Ch1, 'OCSM 2 Channel 1'],
  [21, A380Failure.Ocsm2Ch2, 'OCSM 2 Channel 2'],
  [21, A380Failure.Ocsm3Ch1, 'OCSM 3 Channel 1'],
  [21, A380Failure.Ocsm3Ch2, 'OCSM 3 Channel 2'],
  [21, A380Failure.Ocsm4Ch1, 'OCSM 4 Channel 1'],
  [21, A380Failure.Ocsm4Ch2, 'OCSM 4 Channel 2'],
  [21, A380Failure.AgsApp1, 'AGS Application in CPIOM B1'],
  [21, A380Failure.AgsApp2, 'AGS Application in CPIOM B2'],
  [21, A380Failure.AgsApp3, 'AGS Application in CPIOM B3'],
  [21, A380Failure.AgsApp4, 'AGS Application in CPIOM B4'],
  [21, A380Failure.TcsApp1, 'TCS Application in CPIOM B1'],
  [21, A380Failure.TcsApp2, 'TCS Application in CPIOM B2'],
  [21, A380Failure.TcsApp3, 'TCS Application in CPIOM B3'],
  [21, A380Failure.TcsApp4, 'TCS Application in CPIOM B4'],
  [21, A380Failure.VcsApp1, 'VCS Application in CPIOM B1'],
  [21, A380Failure.VcsApp2, 'VCS Application in CPIOM B2'],
  [21, A380Failure.VcsApp3, 'VCS Application in CPIOM B3'],
  [21, A380Failure.VcsApp4, 'VCS Application in CPIOM B4'],
  [21, A380Failure.CpcsApp1, 'CPCS Application in CPIOM B1'],
  [21, A380Failure.CpcsApp2, 'CPCS Application in CPIOM B2'],
  [21, A380Failure.CpcsApp3, 'CPCS Application in CPIOM B3'],
  [21, A380Failure.CpcsApp4, 'CPCS Application in CPIOM B4'],

  [22, A380Failure.FmcA, 'FMC-A'],
  [22, A380Failure.FmcB, 'FMC-B'],
  [22, A380Failure.FmcC, 'FMC-C'],
  [22, A380Failure.Rollout, 'ROLLOUT'],

  [23, A380Failure.AudioManagementUnit1, 'AMU 1'],
  [23, A380Failure.AudioManagementUnit2, 'AMU 2'],
  [23, A380Failure.RadioManagementPanel1, 'RMP 1'],
  [23, A380Failure.RadioManagementPanel2, 'RMP 2'],
  [23, A380Failure.RadioManagementPanel3, 'RMP 3'],
  [23, A380Failure.Vhf1, 'VHF 1'],
  [23, A380Failure.Vhf2, 'VHF 2'],
  [23, A380Failure.Vhf3, 'VHF 3'],

  [24, A380Failure.TransformerRectifier1, 'TR 1'],
  [24, A380Failure.TransformerRectifier2, 'TR 2'],
  [24, A380Failure.TransformerRectifier3, 'TR ESS'],
  [24, A380Failure.TransformerRectifier4, 'TR APU'],
  [24, A380Failure.StaticInverter, 'Static Inverter'],
  [24, A380Failure.Generator1, 'Generator 1'],
  [24, A380Failure.Generator2, 'Generator 2'],
  [24, A380Failure.Generator3, 'Generator 3'],
  [24, A380Failure.Generator4, 'Generator 4'],
  [24, A380Failure.ApuGenerator1, 'APU Generator 1'],
  [24, A380Failure.ApuGenerator2, 'APU Generator 2'],
  [24, A380Failure.AlternatingCurrent1, 'AC 1'],
  [24, A380Failure.AlternatingCurrent2, 'AC 2'],
  [24, A380Failure.AlternatingCurrent3, 'AC 3'],
  [24, A380Failure.AlternatingCurrent4, 'AC 4'],
  [24, A380Failure.AlternatingCurrentEssential, 'AC EMER'],
  [24, A380Failure.AlternatingCurrentEssentialShed, 'AC ESS'],
  [24, A380Failure.AlternatingCurrent_247XP, 'AC 247XP'],
  [24, A380Failure.AlternatingCurrentGndFltService, 'AC GND FLT SRV'],
  [24, A380Failure.DirectCurrent1, 'DC 1'],
  [24, A380Failure.DirectCurrent2, 'DC 2'],
  [24, A380Failure.DirectCurrentEssential, 'DC ESS'],
  [24, A380Failure.DirectCurrent_247PP, 'DC 247PP'],
  [24, A380Failure.DirectCurrent_309PP, 'DC 309PP'],
  [24, A380Failure.DirectCurrentHot1, 'DC HOT 1'],
  [24, A380Failure.DirectCurrentHot2, 'DC HOT 2'],
  [24, A380Failure.DirectCurrentHot3, 'DC HOT ESS'],
  [24, A380Failure.DirectCurrentHot4, 'DC HOT APU'],
  [24, A380Failure.DirectCurrentGndFltService, 'DC GND FLT SRV'],

  [26, A380Failure.Engine1Fire, 'Fire - Engine 1'],
  [26, A380Failure.Engine2Fire, 'Fire - Engine 2'],
  [26, A380Failure.Engine3Fire, 'Fire - Engine 3'],
  [26, A380Failure.Engine4Fire, 'Fire - Engine 4'],
  [26, A380Failure.APUFire, 'Fire - APU'],
  [26, A380Failure.MLGFire, 'Fire - Main Landing Gear Bay'],
  [26, A380Failure.Engine1LoopA, 'Engine 1 Loop A'],
  [26, A380Failure.Engine1LoopB, 'Engine 1 Loop B'],
  [26, A380Failure.Engine2LoopA, 'Engine 2 Loop A'],
  [26, A380Failure.Engine2LoopB, 'Engine 2 Loop B'],
  [26, A380Failure.Engine3LoopA, 'Engine 3 Loop A'],
  [26, A380Failure.Engine3LoopB, 'Engine 3 Loop B'],
  [26, A380Failure.Engine4LoopA, 'Engine 4 Loop A'],
  [26, A380Failure.Engine4LoopB, 'Engine 4 Loop B'],
  [26, A380Failure.APULoopA, 'APU Loop A'],
  [26, A380Failure.APULoopB, 'APU Loop B'],
  [26, A380Failure.MLGLoopA, 'Main Landing Gear Bay Loop A'],
  [26, A380Failure.MLGLoopB, 'Main Landing Gear Bay Loop B'],

  [27, A380Failure.Prim1, 'PRIM 1'],
  [27, A380Failure.Prim2, 'PRIM 2'],
  [27, A380Failure.Prim3, 'PRIM 3'],
  [27, A380Failure.Sec1, 'SEC 1'],
  [27, A380Failure.Sec2, 'SEC 2'],
  [27, A380Failure.Sec3, 'SEC 3'],
  [27, A380Failure.Fcdc1, 'FCDC 1'],
  [27, A380Failure.Fcdc2, 'FCDC 2'],

  [29, A380Failure.GreenReservoirLeak, 'Green reservoir leak'],
  [29, A380Failure.YellowReservoirLeak, 'Yellow reservoir leak'],
  [29, A380Failure.GreenReservoirAirLeak, 'Green reservoir air leak'],
  [29, A380Failure.YellowReservoirAirLeak, 'Yellow reservoir air leak'],
  [29, A380Failure.GreenReservoirReturnLeak, 'Green reservoir return leak'],
  [29, A380Failure.YellowReservoirReturnLeak, 'Yellow reservoir return leak'],
  [29, A380Failure.GreenElecPumpAOHeat, 'Green A elec pump overheat'],
  [29, A380Failure.GreenElecPumpBOHeat, 'Green B elec pump overheat'],
  [29, A380Failure.YellowElecPumpAOHeat, 'Yellow A elec pump overheat'],
  [29, A380Failure.YellowElecPumpBOHeat, 'Yellow B elec pump overheat'],
  [29, A380Failure.EnginePump1AOHeat, 'Engine 1 pump A overheat'],
  [29, A380Failure.EnginePump1BOHeat, 'Engine 1 pump B overheat'],
  [29, A380Failure.EnginePump2AOHeat, 'Engine 2 pump A overheat'],
  [29, A380Failure.EnginePump2BOHeat, 'Engine 2 pump B overheat'],
  [29, A380Failure.EnginePump3AOHeat, 'Engine 3 pump A overheat'],
  [29, A380Failure.EnginePump3BOHeat, 'Engine 3 pump B overheat'],
  [29, A380Failure.EnginePump4AOHeat, 'Engine 4 pump A overheat'],
  [29, A380Failure.EnginePump4BOHeat, 'Engine 4 pump B overheat'],

  [31, A380Failure.Fws1, 'FWS 1'],
  [31, A380Failure.Fws2, 'FWS 2'],
  [31, A380Failure.Fws1AudioFunction, 'FWS 1 Audio Function'],
  [31, A380Failure.Fws2AudioFunction, 'FWS 2 Audio Function'],
  [31, A380Failure.FwsEcp, 'ECAM Control Panel'],

  [32, A380Failure.LgciuPowerSupply1, 'LGCIU 1 Power supply'],
  [32, A380Failure.LgciuPowerSupply2, 'LGCIU 2 Power supply'],
  [32, A380Failure.LgciuInternalError1, 'LGCIU 1 Internal error'],
  [32, A380Failure.LgciuInternalError2, 'LGCIU 2 Internal error'],

  [32, A380Failure.GearProxSensorDamageGearUplockNose1, 'Proximity sensor damage uplock nose gear #1'],

  [34, A380Failure.RadioAltimeter1, 'RA SYS A'],
  [34, A380Failure.RadioAltimeter2, 'RA SYS B'],
  [34, A380Failure.RadioAltimeter3, 'RA SYS C'],
  [34, A380Failure.RadioAntennaInterrupted1, 'RA SYS A Interrupted'],
  [34, A380Failure.RadioAntennaInterrupted2, 'RA SYS B Interrupted'],
  [34, A380Failure.RadioAntennaInterrupted3, 'RA SYS C Interrupted'],
  [34, A380Failure.RadioAntennaDirectCoupling1, 'RA SYS A Direct Coupling'],
  [34, A380Failure.RadioAntennaDirectCoupling2, 'RA SYS B Direct Coupling'],
  [34, A380Failure.RadioAntennaDirectCoupling3, 'RA SYS C Direct Coupling'],
  [34, A380Failure.Terr1, 'TERR 1'],
  [34, A380Failure.Terr2, 'TERR 2'],
  [34, A380Failure.Gpws1, 'GPWS 1'],
  [34, A380Failure.Gpws2, 'GPWS 2'],
  [34, A380Failure.Transponder1, 'XPDR 1'],
  [34, A380Failure.Transponder2, 'XPDR 2'],

  [46, A380Failure.NssAnsu1, 'NSS AVNCS ANSU 1'],
  [46, A380Failure.NssAnsu2, 'NSS AVNCS ANSU 2'],
  [46, A380Failure.FltOpsAnsu, 'FLT OPS ANSU'],
  [46, A380Failure.CaptainLaptop, 'Captain Laptop'],
  [46, A380Failure.FirstOfficerLaptop, 'F/O Laptop'],
  [46, A380Failure.CaptainOit, 'Captain OIT'],
  [46, A380Failure.FirstOfficerOit, 'F/O OIT'],
];
